package com.time.thread.jiaohu;

/**
 * @program: tes
 * @description:
 * @author: xuejingjing
 * @create: 2021-10-19 13:45
 **/
public class MianTest {
    public static void main(String[] args) {
            //线程还可以携带其他线程，执行其他线程的方法。
            SynchronizedThread synchronizedThread = new SynchronizedThread();
            Thread thread1= new Thread(synchronizedThread,"A");
            Thread thread2= new Thread(synchronizedThread,"B");
            Thread thread3= new Thread(synchronizedThread,"C");
            Thread thread4= new Thread(synchronizedThread,"D");
            thread1.start();
            thread2.start();
            thread3.start();
            thread4.start();


//          2.GongXiangThread();

//1.        buGongXiangThread();
    }

    public static void GongXiangThread() {
        /**
         * 那也就意味着构造函数Thread（Runnable target）不光可以传入Runnable接口的对象，
         *  还可以传入一个Thread类的对象，
         *  这样做完全可以将一个Thread对象中的run（）方法交由其他的线程进行调用。
          */
        GongXiangThread gongXiangThread = new GongXiangThread();
        Thread threadA = new Thread(gongXiangThread,"A");
        Thread threadB = new Thread(gongXiangThread,"b");
        Thread threadC = new Thread(gongXiangThread,"c");
        Thread threadD = new Thread(gongXiangThread,"d");
        threadA.start();
        threadB.start();
        threadC.start();
        threadD.start();
        //这就相当于创建5个线程，调用同一个线程里面的run方法。
    }

    public static void buGongXiangThread() {
        //这个对象就根据类模板,就有了线程name和count值
        //还有，这三个线程之间开启的顺序也不是按照代码的顺序。
        BuGongXiangThread a = new BuGongXiangThread("东风号");
        BuGongXiangThread b = new BuGongXiangThread("神舟号");
        BuGongXiangThread c = new BuGongXiangThread("长征号");
        a.start();
        b.start();
        c.start();
    }
}
